<?php
/**
 * 账单
 */
namespace App\Http\ControllersAdmin;

use App\Service\MemberSubsService;
use App\Validation\DeleteValidation;
use App\Validation\MemberSubsValidation;
use App\Validation\ListValidation;

class MemberSubsController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new ListValidation, $this->request->getJsonRawBody());

		$data = MemberSubsService::getSearch($raw);
		$count = MemberSubsService::getSearch($raw, TRUE);

        $assign = [
            'total' => $count,
            'list'  => $data
        ];

		return $this->echoJson($assign);
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = MemberSubsService::getInfo($id);
		$data->content = json_decode($data->content);
		return $this->echoJson($data);
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = MemberSubsService::forever($raw->id);
		return $this->echoJson('ok');
	}
}